package other;

import java.io.File;
import java.io.Serializable;
import java.util.ArrayList;
import java.util.List;

import android.os.Environment;

public class FileInfo implements Serializable {
	private static final long serialVersionUID = -3456456456451135225L;
	private String name;
	private String type;
	private String size;
	private String path;
        
        public FileInfo(){};
        public FileInfo(String name1,String type1,String size1,String path1){
        	name= name1; type= type1;
        	size= size1; path= path1;
        }
        
	public void setname(String a){name =a ;}
	public void settype(String a){type =a ;}
        public void setsize(String a){size =a ;}
	public void setpath(String a){path =a ;}
	
        public String getname(){return name;}
        public String gettype(){return type ;}
        public String getsize(){return size;}
        public String getpath(){return path ;}
        
        
        public List<FileInfo> getfile(String p){
        	List<FileInfo> ftable= new ArrayList<FileInfo>();
        	File mfile;
        	if(p.equals("")){
        	 mfile=new File(Environment.getExternalStorageDirectory().getPath());}
        	else { mfile=new File(p);
        	String x=Environment.getExternalStorageDirectory().getPath();
        	int r=x.lastIndexOf("/");
        	x=x.substring(0,r);
        	if(!mfile.getParent().equals(x)){ftable.add(new FileInfo("..","d","Directory",mfile.getParent()));}
        	}
        		if (mfile != null && mfile.isDirectory()){
            	
        	File[] list=mfile.listFiles();

        	if(list !=null){
        	 for( int i=0; i< list.length; i++)
        	    {
        	         String name = list[i].getName();
        	         boolean dir =list[i].isDirectory() ;
        	         String type = "f";
        	         if(dir==true){type = "d";}
        	         
        	         String size=String.valueOf( list[i].length() );
        	         String path=list[i].getAbsolutePath();
        	         ftable.add(new FileInfo(name,type,size,path));
        	    }
        	}
        	if(list ==null){ftable.add(new FileInfo("Empty","f","Empty","Empty"));}
        		}
        		if (mfile == null ){ftable.add(new FileInfo("Empty","f","Empty","Empty"));}
        		
        	return ftable;
        }


}
